package com.hzqy.service.activity.load;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Map;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.hzqy.commons.utils.DateUtil;
import com.hzqy.service.activity.interf.ActivityCountAbstract;
import com.hzqy.web.vo.activity.AcContentActionVo;


public class WeekActivityCount implements ActivityCountAbstract {
	private static final Log LOG = LogFactory.getLog(WeekActivityCount.class);
	/**
	 * 当前周体验次数(答题活动)
	 */
	public Map getActivityCount(Map map) {
		if(map != null){
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
			//查找活动对象
			AcContentActionVo acContentActionVo = null;
			if(map.get("actionVo") != null){
				acContentActionVo = (AcContentActionVo)map.get("actionVo");
			}
			int firstWeek = 2;//以活动的开始时间为第一天
			if(acContentActionVo != null){
				 SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
				try {
					firstWeek = DateUtil.getNowWeek(sdf2.parse(acContentActionVo.getF_aca_startdate()));
				} catch (ParseException e) {
					e.printStackTrace();
				}
			}
			//当前周的起始时间
			Date startDate = DateUtil.getAnotherWeekDay(new Date(), 0, firstWeek,firstWeek);
			String startStr = sdf.format(startDate);
			//当前周的结束时间
			int dif = (firstWeek-1)<=0?7:(firstWeek-1);//起始时间的前一个星期
			Date endDate = DateUtil.getAnotherWeekDay(new Date(),0,dif,firstWeek);
			String endStr = sdf.format(endDate);
			
			//awardUserVo.setStartWeek(startStr);
			//awardUserVo.setEndWeek(endStr);
			map.put("startWeek", startStr);
			map.put("endWeek", endStr);
			return map;
			//return activityDao.getAwardCountWeek(awardUserVo);
		}else{
			return null;
		}
	}
	/*
	public static void main(String[] args) throws ParseException {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		Date s = DateUtil.getAnotherWeekDay(sdf.parse("2014-01-25 15:53:41"), 0, Calendar.SUNDAY);
		System.out.println(sdf.format(s));
	}*/
}
